
<h3 id="comments" {% if not entry.comments.count%} style="display:none"{%endif%}>&#8220;{{entry.title}}&#8221; 共有<span style='color:red;font-weight:bold;padding:0px 3px'>{{entry.comments.count}}</span>条留言</h3>
<ol id="commentlist" class="commentlist">
	{% for comment in entry.comments %}
	<li class="{%cycle alt1,alt %}" id="comment-{{comment.key.id}}">
		<div class="gravatar"><img height="50" width="50" class="avatar avatar-50" src="{{comment.gravatar_url}}" alt=""/></div>
		<div class="comments">
			{%if comment.weburl %}
				<a href="{{comment.weburl}}" target="_blank">{{comment.author}}</a>
			{% else %}
				{{comment.author}}
			{%endif%}
			&nbsp;发表于：<small class="commentmetadata"><a href="#comment-{{comment.key.id}}" title="">{{comment.date|datetz:"Y-m-d H:i"}}</a> </small>
			<br />
			<p>{{comment.content}}</p>
		</div>
		<div style="clear:both"></div>
	</li>
	{% endfor %}
</ol>



<h3 id="respond">我要留言</h3>
<div class="info" id="comment_info"></div>
<form action="/post_comment" method="post" id="commentform">
	<div id="comment_area">
		<input type="text" name="author" id="author"  size="25" tabindex="1" />
		<label for="author">名字(name) <span style='color:red'>*</span></label>

		<br/><input type="text" name="email" id="email"  size="25" tabindex="2" />
		<label for="email">邮件(email) <span style='color:red'>*</span></label>

		<br/><input type="text" name="url" id="url"  size="25" tabindex="3" />
		<label for="url">博客/网站(web/blog)</label>

		<p id="checkarea">麻烦，计算一下：<span style="color:#D50000" id="disp_check">{{checknum1}}+{{checknum2}}</span>
		<input type="hidden" name="checknum" id="checknum" value="{{checknum1}}+{{checknum2}}" />
		<input type="text" name="checkret" id="checkret" value="" size="5" tabindex="4" />
		</p>
	</div>

	<p><textarea name="comment" id="comment" style="width:96%"  rows="10" tabindex="4"></textarea></p>
	<div id="s_msg" style="display:none;color:red">正在提交留言...</div>
	<p><input name="submit" type="submit" id="submit" tabindex="5" value="提交留言"/>
	<input type="hidden" name="key" value="{{entry.key}}" />
	<input type="hidden" name="useajax" value="1" />
	</p>
</form>

<script>
       loadjs=false;

       commentuser=$.cookie('comment_user');
       if (commentuser)
       {
         [user,email,url]=commentuser.split('#@#');
         $('#author').val(user);
         $('#email').val(email);
         $('#url').val(url);
         $('#checkarea').hide();
       }
       else
       {
       	num1=Math.round(Math.random()*10);
       	num2=Math.round(Math.random()*10);
       	$('#checkarea #checknum').val(num1+'+'+num2);
       	$('#checkarea #disp_check').text(num1+'+'+num2+'=');
       	$('#checkarea').show();
       }

       function showinfo(msg)
       {
       	  alert(msg);
       }
       function add_comment(msg)
       {
       	  comment=$(msg)
       	  if (!loadjs)
       	  {
       	  	$("#commentlist").append(comment).show();
       	  	$.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function(){
       	  		 comment.animate( { backgroundColor: '#fbc7c7' }, "slow")
       						.animate( { backgroundColor: 'white' }, "slow")
							loadjs=true;
						});
       	  }else
       	  {
       	  	$("#commentlist").append(comment);
       	  	  comment.animate( { backgroundColor: '#fbc7c7' }, "slow")
       						.animate( { backgroundColor: 'white' }, "slow")

       	  }
       }

$('#commentform').ajaxForm({
	type:'post',
	dataType:  'json',
	beforeSubmit:function(formData,jqForm,options){
		   var form = jqForm[0];
		   if (form.author)
		   {
				 if (!form.author.value)
				 {
				  showinfo('请输入你的名字!');
				  form.author.focus();
				  return false;
				 }
				 if (!form.email.value)
				 {
					showinfo('请输入邮件地址');
					form.email.focus();
					return false;
				 }
		   }
			if ($('#checkarea').css('display')!='none')
						   {
							 if(eval(form.checknum.value)!=form.checkret.value)
							 {
							   alert('计算错误，这个算术好像在幼儿园学过的吧？');
							   form.checkret.value='';
							   form.checkret.focus();
							   return false;
							 }

						   }

			 if (!form.comment.value)
			 {
				showinfo('请输入留言内容');
				form.comment.focus();
				return false;
			 }

			 $('#s_msg').text('正在提交留言...').show();

			 return true;
		},
	success:function(data){
		  if (data[0])
		  {
			/*document.cookie=data[2];*/
			add_comment(data[1]);
			$('#s_msg').text('留言提交成功！');
			$('#comment').val('');
		  }
		  else
		  {  if (data[1]==-102)
			 showinfo('计算错误，回幼儿园进修一下再来过。');
			 $('#s_msg').text('留言提交失败！');
			 $('#checkret').focus();
		  }
		}
});
</script>